package com.libraryManage.controller;


import com.libraryManage.commons.utils.ResponseEntity;
import com.libraryManage.commons.utils.PageUtil;
import com.libraryManage.entity.ManagerDo;
import com.libraryManage.service.ManagerService;
import com.libraryManage.vo.ManagerVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import org.apache.shiro.authz.annotation.RequiresAuthentication;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author yf
 * @since 2020-10-22
 */
@Api(tags={"登录接口"})
@RestController
@CrossOrigin
@RequestMapping("/manager/login")
public class ManagerController {

    @Autowired
    ManagerService managerService;

    @ApiOperation("测试接口")
    @ApiResponses({
            @ApiResponse(code=0, message="成功"),
            @ApiResponse(code=500, message="系统异常"),
            @ApiResponse(code=999, message="未登录"),
            @ApiResponse(code=1000, message="数据有效性检查不通过"),
            @ApiResponse(code=1001, message="业务规则检查不通过")
    })
    @RequestMapping(value = "/index" , method = RequestMethod.GET)
    public ResponseEntity<List<ManagerDo>> testIndex(){
        return managerService.getAllManager();
    }

    @RequiresAuthentication//需要经过认真之后才能访问该接口
    @ApiOperation("管理员登录接口")
    @ApiResponses({
            @ApiResponse(code=0, message="成功"),
            @ApiResponse(code=500, message="系统异常"),
            @ApiResponse(code=999, message="未登录"),
            @ApiResponse(code=1000, message="数据有效性检查不通过"),
            @ApiResponse(code=1001, message="业务规则检查不通过")
    })
    @RequestMapping(value = "/test" , method = RequestMethod.GET)
    public ResponseEntity<ManagerDo> login(){

        ManagerDo managerDo = managerService.getManagerById("123");
        ResponseEntity<ManagerDo> res = new ResponseEntity<>(managerDo);
        return res;

    }

}
